package com.paomi.client.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;


import com.paomi.client.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShareDialog extends Dialog {

    @BindView(R.id.ll_qq)
    LinearLayout ll_qq;

    Context context;
    ShareDialog dialog;
    dialogClick click;


    public ShareDialog(@NonNull Context context, dialogClick click) {
        super(context);
        this.context = context;
        this.click = click;
    }

    public ShareDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }


    public ShareDialog creat() {
        dialog = new ShareDialog(context, R.style.Theme_ShareDialog);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_share, null);
        ButterKnife.bind(this, view);
//获得dialog的window窗口
        Window window = dialog.getWindow();
        //设置dialog在屏幕底部
        window.setGravity(Gravity.BOTTOM);
        //设置dialog弹出时的动画效果，从屏幕底部向上弹出
//        window.setWindowAnimations(R.style.dialogStyle);
        window.getDecorView().setPadding(0, 0, 0, 0);
        //获得window窗口的属性
        android.view.WindowManager.LayoutParams lp = window.getAttributes();
        //设置窗口宽度为充满全屏
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        //设置窗口高度为包裹内容
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //将设置好的属性set回去
        window.setAttributes(lp);
        //将自定义布局加载到dialog上
        dialog.getWindow().setContentView(view);
        return dialog;
    }

    @OnClick(R.id.dismiss)
    void xs() {
        dialog.dismiss();
    }

    @OnClick(R.id.ll_qq)
    void qq() {
        if (click != null) {
            dialog.dismiss();
            click.qqClick();
        }
    }

    @OnClick(R.id.ll_qz)
    void qz() {//复制
        if (click != null) {
            dialog.dismiss();
            click.qzClick();
        }
    }

    @OnClick(R.id.ll_wx)
    void wx() {
        if (click != null) {
            dialog.dismiss();
            click.wxClick();
        }
    }

    @OnClick(R.id.ll_wb)
    void wb() {
        if (click != null) {
            dialog.dismiss();
            click.wbClick();
        }
    }

    @OnClick(R.id.ll_pyq)
    void pyq() {
        if (click != null) {
            dialog.dismiss();
            click.pyqClick();
        }
    }


    public interface dialogClick {
        void qqClick();

        void qzClick();

        void wxClick();

        void wbClick();

        void pyqClick();
    }

}
